<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!--引用CW标签  -->
<%@ taglib uri="/WEB-INF/taglib/cw" prefix="CW" %>
<!--引用struts标签  -->
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--通用js  -->
	<script type="text/javascript" src="<%=basePath%>js/commons/common_list.js"></script>
	<link href="<%=basePath%>css/en/list.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="user/getAllUser.action" name="srcForm" id="UserListForm" method="post">
<s:hidden name="actionResult" id="actionResult"  ></s:hidden>
<div class="pageheader">
	<div class="pagetitle">
	<!-- 模块名称  -->
	<s:text name="用户管理" />
	</div>
	<!-- 列表头 -->
	<div class="pageheadercontent">
		<!-- 查询条件 -->
		<table class="searchtbl">
			<tr>
	            <th width="15%">
	            	账号：
	            </th>
	            <td width="18%">
	           		<input type="text" name="userInfo.UserName" id="UserName" value="<s:property value="userInfo.UserName" />">
	            </td>
	            <th width="15%">真实姓名：</th>
	            <td width="18%">
	           		<input type="text" name="userInfo.FullName" id="FullName" value="<s:property value="userInfo.FullName" />">
	           	</td>
            </tr>
			<tr>
				<td colspan="4" style="text-align: center;">
				<input type="button" class="searchbtn" value="搜索" onclick="_search();">
             	<input type="button" class="resetbtn" value="重置" onclick="_reset()">
				</td>
			</tr>
		</table>
		<!-- 工具栏 -->
		<div class="toolbar">
			<!-- 操作 -->
			<div class="toolbarright">
				<input name="add" type="button" value="分配账号" class="addbtn" onclick="_add();return false;">
				<input name="delete" type="button" value="删除" class="delbtn" onclick="_delete();return false;">
				<input name="refresh" type="button" value="刷新" class="refbtn" onclick="_resresh();return false;">
			</div>
		</div>
	</div>
</div>
<!-- 列表内容 -->
<table class="gridview">
<thead>
	<tr class="gridview_color">
		<th width="5%"><input type="checkbox" name="chk_all" id="chk_all"  />
		</th>
		<th width="5%">序号</th>
		<th width="15%">账号</th>
		<th width="25%">真实姓名</th>
		<th >创建人</th>
		<th >创建时间</th>
		<th >状态</th>
		<th width="80px">操作</th>
	</tr>
	</thead>
	<tbody>
	<s:if test="page.resultList.size()>0">
		<s:iterator value="page.resultList" var="user" status="status"  > 
		<tr <s:if test="%{#status.count%2 == 0}">class="gridview_color"</s:if>>
			<td><input type="checkbox" name="chk_list" id="chk_list_<s:property value="#status.count" />" value="<s:property value="UserId" />"/>
			</td>
			<td><s:property value="#status.count" /></td>
			<td title="<s:property value="UserName" />"><s:property value="UserName" /></td>
			<td title="<s:property value="FullName" />"><s:property value="FullName" /></td>
			<td><CW:dataValue property="CreatePerson" field="CreatePerson" person="true"></CW:dataValue></td>
			<td><s:date name="CreateTime" format="yyyy/MM/dd hh:mm:ss" /></td>
			<td><input type="button"class="<s:if test="%{Status == 0}">statusDisabled</s:if><s:if test="%{Status == 1}">statusEnabled</s:if>"
				name="<s:if test="%{Status == 0}">1</s:if><s:if test="%{Status == 1}">0</s:if>" id="<s:property value="UserId" />"
				onclick="_changeStatus(this);return false;">
			</td>
			<td>
			<img  id="divOperation<s:property value="UserId" />" src="images/buttonicon/operation.png" class="operationbtn" onclick="display('<s:property value="UserId" />',event)"  >
			<div id="divhidden<s:property value="UserId" />" class="listmenu" style="display: none;" onmouseleave="onhidden('<s:property value="UserId" />')" >
				<ul>
		 			<li><a href="#" onclick="_modify('<s:property value="UserId" />');return false;">修改</a>
		 			</li>
					<li><a href="#" onclick="_deleteOne('<s:property value="UserId" />');return false;">删除</a>
					</li>
					<li><a href="#" onclick="_reserPwd('<s:property value="UserId" />');return false;">重置密码</a>
					</li>
					<li><a href="#" onclick="_roleSel('<s:property value="UserId" />');return false;">角色设置</a>
					</li>
				</ul>
			</div>
			</td>
		</tr>
		</s:iterator>
	</s:if>
	</tbody>
</table>
<s:else>
	<jsp:include page="../../../common/nullPage.jsp" />
</s:else>
<!--分页条-->
<CW:page property="page" url="/user/getAllUser.action"></CW:page>
</form>
<span class="_height"></span>
<script type="text/javascript">
	//删除
	function _deleteOne(id){
		art.dialog.confirm('确认删除用户', 
		function(){
			document.srcForm.action="<%=basePath%>/user/deleteUser.action?UserId="+id;
			document.srcForm.submit();
		}, function(){
		    art.dialog.tips('操作取消');
		});
	}
	//批量删除用户
	function _delete(){
		var ids = getCheckedValue(); 
		if(ids==""||ids==null){
			art.dialog.alert('没有选择用户');
		}else{
			art.dialog.confirm('确认删除所选用户', 
			function(){
				document.srcForm.action="<%=basePath%>user/deleteUserBatch.action?UserId="+ids;
				document.srcForm.submit();
			}, function(){
			    art.dialog.tips('操作取消');
			});
		}
	}
	//新增
	function _add() {
		 //设置请求的url 
		var _url = "<%=basePath%>user/toAddUser.action";
		document.srcForm.action=_url;
		document.srcForm.submit();
	}
	
	//分配账号
	function _addAccount() {
		 //设置请求的url 
		var _url = "<%=basePath%>user/addAccount.action";
		document.srcForm.action=_url;
		document.srcForm.submit();
	}
	
	//修改用户
	function _modify(UserId) {
		 //设置请求的url 
		var _url = "<%=basePath%>user/modifyUser.action?UserId="+UserId;
		document.srcForm.action=_url;
		document.srcForm.submit();
	}
	//查询一条数据
	function _detail(UserId){
	 	//设置请求的url 
		var _url = "<%=basePath%>user/detailUser.action?UserId="+UserId;
		document.srcForm.action=_url;
		document.srcForm.submit();
	}
	//刷新页面
	function _resresh(){
		$("#UserName").val("");
		$("#FullName").val("");
		$("#Status").val("");
		document.srcForm.action="<%=basePath%>/user/getAllUser.action";
		document.srcForm.submit();
	}
	//重置密码  进行判断 如果有账号才能重置 没有账号不能重置
	function _reserPwd(UserId){
		art.dialog.confirm('确定重置密码', function(){
			$.ajax({  
				    type: "post",  
				    async: false,
				    url: "<%=basePath%>/userAjax/resetPwd.action",  
				    data: "UserId=" + UserId+"&IsReserved=no",  
				    success: function(data){ 
				    	if(data=='false'){
				    		art.dialog.tips('重置密码失败');
				    	}else{
				    		art.dialog.tips('重置密码成功:'+data);
				    	}
				    }
			});
		}, function(){
			art.dialog.tips('重置密码失败');
		});
	}
	//更改状态
	function _changeStatus(obj){
		art.dialog.confirm('确认修改用户状态', function(){
			var UserId = obj.id;
			var UserStatus = obj.name;
			var UserName;
			var css = "";
			if(UserStatus==1){
				css="statusEnabled";
				UserName = "0";
			}else{
				css = "statusDisabled";
				UserName = "1";
			}
			$.ajax({  
			    type: "post",  
			    async: false,
			    url: "<%=basePath%>/userAjax/changeStatus.action",  
			    data: "UserId=" + UserId +"&UserStatus="+UserStatus,  
			    success: function(data){ 
			    	if(data=='true'){
					    art.dialog.tips('操作成功');
					    $("#"+UserId).attr("class",css);
					    $("#"+UserId).attr("name",UserName);
			    	}else{
			    		art.dialog.tips('操作失败');
			    	}
			    }
			});
		}, function(){
			art.dialog.tips('修改状态失败！');
		});
	}
	function _roleSel(name) {
		//设置请求的url 
		var _url = "<%=basePath%>/tree/RoleTree.action?UserId="+name;
		//调用art.dialog组件弹出窗口 采用iframe方式
		art.dialog.open(_url,
			{ 
			 	lock: true,//背景锁定
		    	background: '#BFBFBF', // 背景色
		    	opacity: 0.5,	// 透明度
				title : '选择角色',
				width: '400px',
				height: '400px',
				drag : false,//禁止拖动
				resize: false,//禁止改变大小
				ok : function() {
	 				var iframe = this.iframe.contentWindow;
					if (!iframe.document.body) {
						art.dialog.tips('页面没有加载完毕！');
						return false;
					}
					var form = iframe.document.getElementById("selUserRoleForm");
					form.submit();
				},
				cancel : true
		}); 
	}
	//分配账号  删除
	function _AccountSel(UserId){
		location.href="<%=basePath%>/user/toUserAccount.action?UserId="+UserId;
		
	}
	//带条件查询
	function _search(){
		document.srcForm.submit();
	}
	function _reset(){
		$("#UserName").val("");
		$("#FullName").val("");
		$("#Status").val("");
	}
	 $(document).ready(function() {
		 //显示操作结果
		 var actionResult = $("#actionResult").val();
		 if(actionResult=="success"){
		 	art.dialog.tips('操作成功');
		 }else if(actionResult=="error"){
		 	art.dialog.tips('操作失败！');
		 }
	});
</script>
</body>
</html>
